{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "49438f3e",
   "metadata": {},
   "source": [
    "## 1.1优化百度ASR接口"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6c87e965",
   "metadata": {},
   "outputs": [],
   "source": [
    "from bdasr import fetch_token,asr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "56dae6e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 以下为asr代码优化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "49faa9ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "# jiezhi : asr\n",
    "API_KEY = 'dzWPEA9d3AGWzzgUE9NWgDZn'\n",
    "SECRET_KEY = '1Q6PA4o6wARvT7BGiLji4XFseCDRD3MP'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3ebad63b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.0717123e774cd3aad92a31073b3296cf.2592000.1655540432.282335-26192424'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jie_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "jie_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "3cb7f139",
   "metadata": {},
   "outputs": [],
   "source": [
    "import speech_recognition\n",
    "\n",
    "r = speech_recognition.Recognizer()\n",
    "\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3a1bf82c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"corpus_no\":\"7099360055709459686\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"你好，北京科技馆。\"],\"sn\":\"387233040541652948570\"}\\n'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "asr(token = jie_token,AUDIO_FILE = '1.wav')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47fcff90",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
